//
//  TFLotteryWinnerListViewController.swift
//  TalkfunSDKDemo
//
//  Created by 邓盛明 on 2022/2/28.
//  Copyright © 2022 Talkfun. All rights reserved.
//

import UIKit


class TFLotteryWinnerListViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.listData.count;
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    
        let cell = UITableViewCell.init(style: .default, reuseIdentifier: "listcell")
     
        let dict = self.listData[indexPath.row] as! TFLotteryWinner
        let nickname = "\(indexPath.row+1)" + dict.nickname
        let attr34: [NSAttributedString.Key : Any] = [.font: UIFont.systemFont(ofSize: 14.7),.foregroundColor: UIColor(red: 125/255.0, green: 78/255.0, blue: 65/255.0, alpha: 1.0),]
     
        let str = NSMutableAttributedString.init(string: nickname, attributes: attr34)
        
        let attr3: [NSAttributedString.Key : Any] = [.foregroundColor: UIColor(red: 190/255.0, green: 120/255.0, blue: 102/255.0, alpha: 1.0),]
        str.addAttributes(attr3, range: NSRange(location: 0, length: 1))
        cell.textLabel?.attributedText = str
        cell.backgroundColor = UIColor.clear

        return cell;
    }
    

    @objc public var tableview:UITableView!
    @objc public var listData:NSMutableArray = NSMutableArray()
    @objc public var closeBtn:TalkfunIncreaseButton!
    var bg_imgview:UIImageView!
    var titleImg:UIImageView!
    var lineV:UIView!
    override func viewDidLoad() {
        super.viewDidLoad()

        self.view.backgroundColor = UIColor(red: 5/255.0, green: 0/255.0, blue: 1/255.0, alpha: 0.8)
        self.bg_imgview = UIImageView.init()
        self.bg_imgview.image = UIImage.init(named: "HTLive.bundle/list_bg")
        self.bg_imgview.isUserInteractionEnabled = true
        self.view.addSubview(self.bg_imgview)
       
        self.titleImg = UIImageView.init()
        self.titleImg.image = UIImage.init(named: "HTLive.bundle/winlist_title")
        self.bg_imgview.addSubview(self.titleImg)
  
        self.closeBtn = TalkfunIncreaseButton.init()
        self.closeBtn.setImage(UIImage.init(named: "HTLive.bundle/nowin_close"), for: .normal)
        self.bg_imgview.addSubview(self.closeBtn)
      
        self.tableview =  UITableView.init()
      
       self.tableview.delegate = self;
       self.tableview.dataSource = self;
        self.tableview.backgroundColor = UIColor.clear
        self.tableview.separatorStyle = .none;
        self.bg_imgview.addSubview(self.tableview)
        self.tableview.dequeueReusableCell(withIdentifier: "listcell")
    
        self.lineV = UIView.init()
        self.lineV.backgroundColor = UIColor(red: 245/255.0, green: 204/255.0, blue: 193/255.0, alpha: 1.0)
     
        self.lineV.layer.cornerRadius = 2.0;
        self.lineV.layer.masksToBounds = true;
        self.bg_imgview.addSubview(self.lineV)
     
       
        self.updateFrame()
    }
    

   @objc public func updateFrame() {
       let width = TalkfunSharedTools.getMainScreen().size.width
       let height = TalkfunSharedTools.getMainScreen().size.height
       if (width > height) {
           if (height < 375) {
               self.bg_imgview.frame = CGRect(x: (width-224)/2, y: (height-280)/2.0, width: 224, height: 280)
           } else {
               self.bg_imgview.frame = CGRect(x: (width-256)/2, y: (height-320)/2, width: 256, height: 320)
           }
       } else {
           if (width < 375) {
               self.bg_imgview.frame = CGRect(x: (width-280)/2, y: (height-250)/2.0, width: 280, height: 350)
           } else {
               self.bg_imgview.frame = CGRect(x: (width-297)/2, y: (height-367)/2.0, width: 297, height: 367)
             
           }
       }
     
       self.titleImg.frame = CGRect(x: (self.bg_imgview.frame.size.width-153)/2.0, y: -17, width: 153, height: 46)
       self.closeBtn.frame = CGRect(x: self.bg_imgview.frame.size.width-33, y: 0, width: 33, height: 33)
       self.tableview.frame = CGRect(x: 30, y: 60, width: 217, height: self.bg_imgview.frame.size.height-60)
       self.lineV.frame = CGRect(x: self.bg_imgview.frame.size.width-22, y: (self.bg_imgview.frame.size.height-80)/2.0, width: 4, height: 40)

    }
    


}
